<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>可用考试列表</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <style>
        .exam-card {
            transition: transform 0.3s, box-shadow 0.3s;
        }
        .exam-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
        }
    </style>
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <div class="container">
            <a class="navbar-brand" href="/dashboard"><i class="fa fa-graduation-cap me-2"></i>学生考试管理系统</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav ms-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="/dashboard"><i class="fa fa-tachometer me-1"></i>仪表盘</a>
                    </li>
                    <li class="nav-item active">
                        <a class="nav-link" href="/exams"><i class="fa fa-list-alt me-1"></i>考试列表</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/logout"><i class="fa fa-sign-out me-1"></i>退出登录</a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <div class="container mt-4">
        <div class="row mb-4">
            <div class="col">
                <h2><i class="fa fa-list-alt me-2"></i>可用考试列表</h2>
                <hr>
            </div>
        </div>

        <!-- 错误提示 -->
        <c:if test="${not empty error}">
            <div class="alert alert-danger alert-dismissible fade show" role="alert">
                <i class="fa fa-exclamation-circle me-2"></i>${error}
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>
        </c:if>

        <!-- 考试列表 -->
        <div class="row">
            <c:forEach var="exam" items="${exams}">
                <div class="col-md-6 col-lg-4 mb-4">
                    <div class="card exam-card h-100">
                        <div class="card-header bg-primary text-white">
                            <h5 class="card-title mb-0">${exam.courseName}</h5>
                        </div>
                        <div class="card-body">
                            <p class="card-text"><strong>考试ID:</strong> ${exam.examId}</p>
                            <p class="card-text"><strong>考试时间:</strong> ${exam.startTime} 至 ${exam.endTime}</p>
                            <p class="card-text"><strong>考试时长:</strong> ${exam.duration}分钟</p>
                            <p class="card-text"><strong>总分:</strong> ${exam.totalScore}分</p>
                        </div>
                        <div class="card-footer bg-transparent d-flex justify-content-between">
                            <small class="text-muted"><i class="fa fa-clock-o me-1"></i>状态: ${exam.status}</small>
                            <a href="/exams/take/${exam.examId}" class="btn btn-primary btn-sm">
                                <i class="fa fa-play-circle me-1"></i>参加考试
                            </a>
                        </div>
                    </div>
                </div>
            </c:forEach>

            <!-- 没有考试时显示 -->
            <c:if test="${empty exams}">
                <div class="col-12 text-center py-5">
                    <i class="fa fa-calendar-times-o fa-5x text-muted mb-3"></i>
                    <h3>暂无可用考试</h3>
                    <p class="text-muted">请联系管理员获取考试信息</p>
                </div>
            </c:if>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
</body>
</html>